package cn.tedu.micro.demo.rabbit.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 声明一套类似tutorail入门案例的组件结构
 * Direct路由交换机 direct_demo_ex(Exchange bean)
 * Queue demo_queue(Queue bean)
 * 确定绑定关系 demo_rk(Binding bean)
 */
@Configuration
@Slf4j
public class DelcareConfiguration {
    /**
     * 声明交换机
     * channel.exchangeDeclare("name",DIRECT)
     */
    @Bean
    public Exchange directDemoEx(){
        //方案1: 直接new 传递参数
        //return new DirectExchange("direct_demo_ex");
        //方案2: 使用框架提供的builder 链式调用
        return ExchangeBuilder.directExchange("direct_demo_ex").build();
    }
    /**
     * channel.queueDelcare("name",false,false,false,null)
     */
    @Bean
    public Queue demoQueue(){
        //方案1:直接new
        //return new Queue("demo_queue",false,false,false,null);
        //方案2: 使用builder
        return QueueBuilder.nonDurable("demo_queue").build();
    }

    /**
     * channel.queueBind("queueName","exName","rk")
     */
    @Bean
    public Binding demoBind(){
        //方案1: 直接new
        //队列绑交换机 QUEUE
        //交换机绑交换机 EXCHANGE
        //return new Binding("demo_queue", Binding.DestinationType.QUEUE,"direct_demo_ex","demo_rk",null);
        //方案2: 使用builder
        return BindingBuilder.bind(demoQueue()).to(directDemoEx()).with("demo_rk").noargs();
    }
    //TODO 思考: 如果我们想要按照demo案例中定义延迟结构的内容,声明组件 在springboot整么实现
}
